package com.dzf.service.impl;

import com.dzf.Util.SessionUtil;
import com.dzf.dao.DiscussDao;
import com.dzf.entity.Discuss;
import com.dzf.entity.User;
import com.dzf.service.DiscussService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class DiscussServiceImpl implements DiscussService {
    @Autowired
    DiscussDao discussDao;
    @Autowired
    SessionUtil sessionUtil;

    @Override
    public boolean addDiscuss(Discuss discuss) {
        if ("".equals(discuss.getDisid())||discuss==null)
        {
            discuss.setLevel(0);
        }
        User user = sessionUtil.getUser();
        discuss.setUsername(user.getName());
        discuss.setUserId(user.getId());
        discuss.setCreateTime(new Date());
        discuss.setModifyTime(new Date());
        return discussDao.addDiscuss(discuss);
    }

    @Override
    public Boolean delDiscuss(Discuss did) {
        return discussDao.delDiscuss(did);
    }

    @Override

    public Map<String, Object> findByDis(String blogid, int pagenum) {
        pagenum = (pagenum*10)-10;
        return discussDao.findByDis(blogid,pagenum);
    }

    @Override
    public List<Discuss> findByDislevel(String disid, int level) {
        return discussDao.findByDislevel(disid,level);
    }

    @Override
    public Map<Object, Object> findByUserDis(String uid, int pagenum, int num) {
        pagenum = (pagenum*10)-10;
        return discussDao.findByUserDis(uid, pagenum, num);
    }

}
